package main

import (
	"crypto/md5"
	"crypto/sha1"
	"encoding/base64"
	"fmt"
)

func main() {
	sha1Encrpyt()
	md5Encrpyt()
	base64Encode()
	base64UrlEncode()
}

func sha1Encrpyt() {
	s := "sha1:this string"

	h := sha1.New()

	h.Write([]byte(s))

	bs := h.Sum(nil)

	fmt.Println(s)
	// 使用16进制打印
	fmt.Printf("%x\n", bs)
}

func md5Encrpyt() {
	s := "md5:this string"

	h := md5.New()

	h.Write([]byte(s))

	bs := h.Sum(nil)

	fmt.Println(s)
	fmt.Printf("%x\n", bs)
}

func base64Encode() {
	s := "base64:abc123~!!@@#!@##$%$%^&&*(&()"

	en := base64.StdEncoding.EncodeToString([]byte(s))
	de, _ := base64.StdEncoding.DecodeString(en)

	fmt.Println(string(de))
	fmt.Println(en)

}

func base64UrlEncode() {
	s := "url: <?>)()912"

	en := base64.URLEncoding.EncodeToString([]byte(s))
	de, _ := base64.URLEncoding.DecodeString(en)

	fmt.Println(string(de))
	fmt.Println(en)
}
